package com.example.administrator.ygddriver.into.login.driverjoin;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.administrator.ygddriver.R;
import com.example.administrator.ygddriver.base.BaseActivity;
import com.example.administrator.ygddriver.base.UserBean;
import com.example.administrator.ygddriver.into.login.driverjoin.small.SmallJoinActivity;
import com.example.administrator.ygddriver.into.login.driverjoin.weight.WeightActivity;
import com.example.administrator.ygddriver.liteorm.LiteOrmTools;
import com.example.administrator.ygddriver.tool.OkGoRequests;
import com.example.administrator.ygddriver.tool.SimpleToolbar;
import com.example.administrator.ygddriver.tool.UrlValuse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 司机加盟
 */
public class DriverJoinActivity extends BaseActivity {
    private SimpleToolbar simpleToolbar;
    private RecyclerView recyclerView;
    private DriverJoinAdapter driverJoinAdapter;
    private String mToken;

    @Override
    public int initLayout() {
        return R.layout.activity_driver_join;
    }

    @Override
    public void initView() {
        simpleToolbar = findViewById(R.id.activity_driver_join_stb);
        recyclerView = findViewById(R.id.activity_driver_join_rv);
    }

    @Override
    public void initDate() {
        LiteOrmTools.getInformation(UserBean.class, this, new LiteOrmTools.On<UserBean>() {
            @Override
            public void hasData(UserBean data) {
                mToken = data.getC_token();
                initDriverTypeHtml(mToken);
            }
        }, new LiteOrmTools.OFF() {
            @Override
            public void noData() {

            }
        });


        driverJoinAdapter = new DriverJoinAdapter(R.layout.item_driver_join, null);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL));
        recyclerView.setAdapter(driverJoinAdapter);
        driverJoinAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                DriverJoinRequestBean.ResultBean.DriverTypesBean driverTypesBean = (DriverJoinRequestBean.ResultBean.DriverTypesBean) adapter.getData().get(position);
                Intent intent = new Intent();
                if (driverTypesBean.getC_drivertype().equals("1")) {
                    intent.setClass(DriverJoinActivity.this, SmallJoinActivity.class);
                } else {
                    intent.setClass(DriverJoinActivity.this, WeightActivity.class);
                    intent.putExtra("c_url", driverTypesBean.getC_url());
                }
                intent.putExtra("c_drivertype", driverTypesBean.getC_drivertype());
                startActivity(intent);
            }
        });
        setSimpleToolbar();
    }

    private void setSimpleToolbar() {
        simpleToolbar.setMainTitle("司机加盟");
        simpleToolbar.setMainTitleColor("#000000");
        simpleToolbar.setToolColor("#ffffff");

    }

    //司机类型列表查询
    private void initDriverTypeHtml(String c_token) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("c_token", c_token);
        hashMap.put("c_type", "2");
        OkGoRequests.getInstance().putRequestAsync(UrlValuse.POST_API_DRIVER + UrlValuse.DRIVER_TYPE, hashMap, DriverJoinRequestBean.class, new OkGoRequests.OnTrue<DriverJoinRequestBean>() {
            @Override
            public void hasData(DriverJoinRequestBean date) {
                if (date.isSuccess()) {
                    driverJoinAdapter.setNewData(date.getResult().getDriverTypes());
                }
            }
        }, new OkGoRequests.OnError<DriverJoinRequestBean>() {
            @Override
            public void noData() {

            }
        });


    }
}
